<?php
include "api.php";
function pagelinks($id,$pages,$page,$mode)
{
    global $config;
    $sl = (int) (($s = $config[$mode]['sidelinks']) > 0) ? $s : 2;
    $mf = ($mode == "topic") ? "tp" : "fp";
    if($page > $pages) $page = 1;
    echo ($page > 1) ? "<a onclick=\"$mf($id,1,$sl);\">" : "<b>";
    echo "&lt;&lt; ";
    echo ($page > 1) ? "</a>" : "</b>";
    if($page <= $sl)
    {
        for($i = 1; $i < $page; $i++) echo "<a onclick=\"$mf($id,$i,$sl);\">$i</a> ";
    }
    else
    {
        for($i = $page-$sl; $i < $page; $i++) echo "<a onclick=\"$mf($id,$i,$sl);\">$i</a> ";
    }
    echo "<b>$page</b>";
    if($page > $pages - $sl)
    {
        for($i = $page+1; $i <= $pages; $i++) echo " <a onclick=\"$mf($id,$i,$sl);\">$i</a>";
    }
    else
    {
        for($i = $page+1; $i <= $page+$sl; $i++) echo " <a onclick=\"$mf($id,$i,$sl);\">$i</a>";
    }
    echo ($page < $pages) ? "<a onclick=\"$mf($id,$pages,$sl);\">" : "<b>";
    echo " >> ";
    echo ($page < $pages) ? "</a>" : "</b>";
    echo "\n";
}
# Thank you, alishahnovin@hotmail.com
function trunc($text,$numb,$etc = "...")
{
    $text = html_entity_decode($text,ENT_QUOTES);
    if (strlen($text) > $numb)
    {
        $text = substr($text, 0, $numb);
        $text = substr($text,0,strrpos($text," "));
        $punct = ".!?:;,-"; # Punctuation you want removed
        $text = (strspn(strrev($text), $punct) != 0) ? substr($text, 0, -strspn(strrev($text), $punct)) : $text;
        $text .= $etc;
    }
    return $text;
}
# Salt generator. Silly name necessary.
function shaker($len = 64)
{
    /* Reference
    ** FeS = Login
    ** NaCl = Original Salt for Topic/Post Validation
    ** NaCN = Topic Validation
    ** NaOH = Post Validation
    ** KCl = Original Salt for Profile/Preferences Edit Validation
    ** KCN = Profile Edit Validation
    ** KOH = Preferences Edit Validation
    */
    srand((double)microtime()*1000000);
    $salt = "";
    for($i = 0; $i < $len; $i++) $salt .= substr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", rand() % 61, 1);
    return $salt;
}
function md5deconf($str) {
    $ret = "";
    $str = str_replace('_','0',$str);
    $str = str_replace('-','1',$str);
    if(strlen($str) % 8 != 0) return false;
    else
    {
        $str = str_split($str,8);
        foreach($str as $s) $ret .= chr(bindec($s));
    }
    return $ret;
}
function rank($uid = 0)
{
    global $api;
    if($uid === 0) $uid = $_COOKIE['ramble_id'];
    $u = $api->get("user","rank",$uid);
    if(!$u) return 0;
    else return $u;
}
# Contact Table
function contacts($contact, $id)
{
?>
<td><img alt="Private Message" title="Private Message" src="images/icons/contact/pm.png" /></td>
<?if($contact['email']){?>
<td><a href="mailto:<?=$contact['email']?>"><img alt="EMail" title="EMail" src="images/icons/contact/email.png" /></a></td>
<?} else echo "\t\t\t<td />\n"?>
<?if($contact['aim']){?>
<td><a href="aim:goim?screenname=<?=$contact['aim']?>"><img alt="AIM" title="AIM" src="images/icons/contact/aim.png" /></a></td>
<?} else echo "\t\t\t<td />\n"?>
<?if($contact['msn']){?>
<td><a onclick="showcont('MSN','<?=$contact['msn']?>','<?=$id?>')"><img alt="MSN" title="MSN" src="images/icons/contact/msn.png" /></a></td>
<?} else echo "\t\t\t<td />\n"?>
<?if($contact['skype']){?>
<td><a href="skype:<?=$contact['skype']?>?chat"><img alt="Skype" title="Skype" src="images/icons/contact/skype.png" /></a></td>
<?} else echo "\t\t\t<td />\n"?>
<?if($contact['gtalk']){?>
<td><a onclick="showcont('GTalk','<?=$contact['gtalk']?>','<?=$id?>')"><img alt="Google Talk" title="Google Talk" src="images/icons/contact/gtalk.png" /></a></td>
<?}else echo "\t\t\t<td />\n"?>
<?php
}
?>